package com.pigs.pigsordersystem.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pigs.pigsordersystem.service.IProductService;
import com.pigs.pigsordersystem.entity.ProductEntity;
import com.pigs.pigsordersystem.mapper.ProductMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Y.yang
 * @since 2020-03-14
 */
@Transactional
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductEntity> implements IProductService {

    @Autowired
    private ProductMapper productMapper;



    @Override
    public List<ProductEntity> queryProductList() {
        List<ProductEntity> productEntities = productMapper.queryProductList();
        return productEntities;
    }

    /**
     * 查询 客户 购买订单 记录
     * 通过用户名字查询
     *
     * @param userName
     * @return
     */
    @Override
    public IPage<ProductEntity> queryOrderList(Page page, String userName) {
        if (userName != null) {

            IPage<ProductEntity> productEntityIPage = productMapper.queryOrderList(page, userName);
            if (productEntityIPage != null) {

                return productMapper.queryOrderList(page, userName);
            }

        }
        return null;
    }
}
